let express=require('express');
let index=require('./node/api/index.js');
let admin=require('./node/api/admin.js');

let app=new express();
//app.use(path,router)
app.use('/index',index)
app.use('/admin',admin)
app.get('/',function(req,res){
    res.redirect('/index');
})


// 请求的url
var url = '/complex.json';
app.get(url, function(req, res) {

    // 默认返回的json 对象
    var obj = {
       data:[
           {cc:112}
       ]
    }
    // 产生一个随机的金额模拟一下可用余额
    var money = Math.floor(Math.random()*10) + 5;

    // 如果请求中有参数 ‘types=ACCOUNT’
    if('types' in  req.query && req.query.types === 'ACCOUNT'){
        obj = {
            "ACCOUNT": {
                "avaiable": money,
                "freezeAmount": 0
            },
            "success": true
        };
    }
    res.jsonp(obj);
});


// app.use(express.static(__dirname+'/node/public'));//读取目录
// app.use('/static',express.static(__dirname+'/node/static'));//读取目录

let server=app.listen(80,'127.0.0.61',function(req,res,next){
    let host=server.address().address
    let port=server.address().port
    console.log("http://%s:%s",host,port)
})